*This is the data analysis part of the program.
*This is used when the variables must be calculated, some more data entered, and then analyzed.
;

PROC IMPORT OUT= WORK.one DATAFILE= "C:\Users\tebert\OneDrive - University of Florida\Work\Manuscipts\Gender size\Final Pieces MS\Final Data.xlsx" 
 DBMS=xlsx REPLACE;
 SHEET="Transformed Variables"; 
 GETNAMES=YES;
RUN;
*/;
/*
PROC IMPORT OUT= WORK.one DATAFILE= "C:\Users\tebert\OneDrive - University of Florida\Work\Manuscipts\Gender size\Final Pieces MS\Final Data.xlsx" 
 DBMS=xlsx REPLACE;
 SHEET="Raw Variables"; 
 GETNAMES=YES;
RUN;
*/;
data one; set one;
if sex="F" or sex="f" then sex="female";
if sex="M" or sex="m" then sex="male";
if color1="B" or color1="b" then color1="blue";
if color1="G" or color1="g" then color1="green";
run;
data one; set one;
  if insectno ne "c04" then output;
run;

/*
data one; set one;
proc sort; by sex;
proc means; by sex;
proc sort; by color1;
proc means; by color1;
proc sort; by sex color1;
proc means; by sex color1;
run;
/*
proc glm plots=diagnostics;
model head=head|femur;
lsmeans sex;
lsmeans color1;
run;


model femur=head|femur;
lsmeans sex;
lsmeans color1;
run;
*/;
data two; set one;
femur=log(femur);
head=log(head);
proc sort; by sex color2;
run;

ods graphics on;
proc glm data=two plots=diagnostics; class sex color2; model NumPrbs=Femur head femur*head/solution;   title 'NumPrbs';
proc glm data=two plots=diagnostics; class sex color2; model MnPrbs=Femur head femur*head/solution;   title 'MnPrbs';
proc glm data=two plots=diagnostics; class sex color2; model sdPrbs=Femur head femur*head/solution;   title 'sdPrbs';
proc glm data=two plots=diagnostics; class sex color2; model MdnPrbs=Femur head femur*head/solution;   title 'MdnPrbs';
proc glm data=two plots=diagnostics; class sex color2; model DurFrstPrb=Femur head femur*head/solution;   title 'DurFrstPrb';
proc glm data=two plots=diagnostics; class sex color2; model DurScndPrb=Femur head femur*head/solution;   title 'DurScndPrb';
proc glm data=two plots=diagnostics; class sex color2; model TtlPrbTm=Femur head femur*head/solution;   title 'TtlPrbTm';*duration of recording less duration of NP or Z;

*******************************************************************;
******** Variables for NP *************************;
*******************************************************************;
proc glm data=two plots=diagnostics; class sex color2; model NumNP=Femur head femur*head/solution;  title 'NumNP';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurNP=Femur head femur*head/solution;  title 'TtlDurNP';
proc glm data=two plots=diagnostics; class sex color2; model MnDurNP=Femur head femur*head/solution;  title 'MnDurNP';
proc glm data=two plots=diagnostics; class sex color2; model sdNP=Femur head femur*head/solution;  title 'sdNP';
proc glm data=two plots=diagnostics; class sex color2; model TmFrstPrbFrmStrt=Femur head femur*head/solution;  title 'TmFrstPrbFrmStrt'; *Duration of first NP;
proc glm data=two plots=diagnostics; class sex color2; model DurScndZ=Femur head femur*head/solution;  title 'DurScndZ'; *Duration of second NP;
proc glm data=two plots=diagnostics; class sex color2; model DurNnprbBfrFrstE1=Femur head femur*head/solution;  title 'DurNnprbBfrFrstE1';
proc glm data=two plots=diagnostics; class sex color2; model DurNpFllwFrstSusE2=Femur head femur*head/solution;  title 'DurNpFllwFrstSusE2';

*******************************************************************;
******** Variables for C or Pathway (=C+A+B) *************;
*******************************************************************;
proc glm data=two plots=diagnostics; class sex color2; model NmbrC=Femur head femur*head/solution;  title 'NmbrC';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurC=Femur head femur*head/solution;  title 'TtlDurC';
proc glm data=two plots=diagnostics; class sex color2; model MnDurC=Femur head femur*head/solution;  title 'MnDurC';
proc glm data=two plots=diagnostics; class sex color2; model sdC=Femur head femur*head/solution;  title 'sdC';
proc glm data=two plots=diagnostics; class sex color2; model NmbrShrtC=Femur head femur*head/solution;  title 'NmbrShrtC';
proc glm data=two plots=diagnostics; class sex color2; model ShrtCbfrE1=Femur head femur*head/solution;  title 'ShrtCbfrE1';
proc glm data=two plots=diagnostics; class sex color2; model PrcntPrbC=Femur head femur*head/solution; title 'PrcntPrbC';

*******************************************************************;
******** Variables for G *************************;
*******************************************************************;
proc glm data=two plots=diagnostics; class sex color2; model NumG=Femur head femur*head/solution;  title 'NumG';
proc glm data=two plots=diagnostics; class sex color2; model DurG=Femur head femur*head/solution;  title 'DurG';
proc glm data=two plots=diagnostics; class sex color2; model MeanG=Femur head femur*head/solution;  title 'MeanG';
proc glm data=two plots=diagnostics; class sex color2; model sdG=Femur head femur*head/solution;  title 'sdG';
proc glm data=two plots=diagnostics; class sex color2; model CtoFrstG=Femur head femur*head/solution;  title 'CtoFrstG';
proc glm data=two plots=diagnostics; class sex color2; model DurNnprbBfrFrstG=Femur head femur*head/solution;  title 'DurNnprbBfrFrstG';
proc glm data=two plots=diagnostics; class sex color2; model meanNGPrb=Femur head femur*head/solution;  title 'meanNGPrb';
proc glm data=two plots=diagnostics; class sex color2; model TmFrmFrstPrbFrstG=Femur head femur*head/solution;  title 'TmFrmFrstPrbFrstG';
proc glm data=two plots=diagnostics; class sex color2; model TmBegPrbFrstG=Femur head femur*head/solution;  title 'TmBegPrbFrstG';
proc glm data=two plots=diagnostics; class sex color2; model NumPrbsAftrFrstG=Femur head femur*head/solution;  title 'NumPrbsAftrFrstG';
proc glm data=two plots=diagnostics; class sex color2; model NmbrShrtPrbAftrFrstG=Femur head femur*head/solution;  title 'NmbrShrtPrbAftrFrstG';
proc glm data=two plots=diagnostics; class sex color2; model NumLngG=Femur head femur*head/solution;  title 'NumLngG';
proc glm data=two plots=diagnostics; class sex color2; model TmFrstSusGFrstPrb=Femur head femur*head/solution;  title 'TmFrstSusGFrstPrb';
proc glm data=two plots=diagnostics; class sex color2; model PrcntPrbG=Femur head femur*head/solution;  title 'PrcntPrbG';

*******************************************************************;
******** Variables for D *************************;
*******************************************************************;
proc glm data=two plots=diagnostics; class sex color2; model NumD=Femur head femur*head/solution; title 'NumD';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurD=Femur head femur*head/solution;  title 'TtlDurD';
proc glm data=two plots=diagnostics; class sex color2; model MeanD=Femur head femur*head/solution; title 'MeanD';
proc glm data=two plots=diagnostics; class sex color2; model sdD=Femur head femur*head/solution; title 'sdD';
proc glm data=two plots=diagnostics; class sex color2; model CtoFrstD=Femur head femur*head/solution;   title 'CtoFrstD';
proc glm data=two plots=diagnostics; class sex color2; model DurNnprbBfrFrstD=Femur head femur*head/solution;   title 'DurNnprbBfrFrstD';
proc glm data=two plots=diagnostics; class sex color2; model meanNDPrb=Femur head femur*head/solution;   title 'meanNDPrb';
proc glm data=two plots=diagnostics; class sex color2; model TmFrmFrstPrbFrstD=Femur head femur*head/solution;   title 'TmFrmFrstPrbFrstD';
proc glm data=two plots=diagnostics; class sex color2; model TmBegPrbFrstD=Femur head femur*head/solution;   title 'TmBegPrbFrstD';
proc glm data=two plots=diagnostics; class sex color2; model NumPrbsAftrFrstD=Femur head femur*head/solution;   title 'NumPrbsAftrFrstD';
proc glm data=two plots=diagnostics; class sex color2; model NmbrShrtPrbAftrFrstD=Femur head femur*head/solution;   title 'NmbrShrtPrbAftrFrstD';
proc glm data=two plots=diagnostics; class sex color2; model NumLngD=Femur head femur*head/solution;   title 'NumLngD';
proc glm data=two plots=diagnostics; class sex color2; model TmFrstSusDFrstPrb=Femur head femur*head/solution;   title 'TmFrstSusDFrstPrb';
proc glm data=two plots=diagnostics; class sex color2; model MaxD=Femur head femur*head/solution;   title 'MaxD';
proc glm data=two plots=diagnostics; class sex color2; model PrcntPrbD=Femur head femur*head/solution;   title 'PrcntPrbD';
*/;
*******************************************************************;
******** Variables for E or E1 *************************;
*******************************************************************;
proc glm data=two plots=diagnostics; class sex color2; model NumE1=Femur head femur*head/solution;   title 'NumE1';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurE1=Femur head femur*head/solution;   title 'TtlDurE1';
***Here is one example MnDurE1;
proc glm data=two plots=diagnostics; class sex color2; model MnDurE1=Femur head femur*head/solution;   title 'MnDurE1';
***And another;
proc glm data=two plots=diagnostics; class sex color2; model sdE1=Femur head femur*head/solution;   title 'sdE1';
proc glm data=two plots=diagnostics; class sex color2; model CtoFrstE1=Femur head femur*head/solution;   title 'CtoFrstE1';
proc glm data=two plots=diagnostics; class sex color2; model TmFrmFrstPrbFrstE=Femur head femur*head/solution;   title 'TmFrmFrstPrbFrstE';
proc glm data=two plots=diagnostics; class sex color2; model TmBegPrbFrstE=Femur head femur*head/solution;   title 'TmBegPrbFrstE';
proc glm data=two plots=diagnostics; class sex color2; model NumPrbsAftrFrstE=Femur head femur*head/solution;   title 'NumPrbsAftrFrstE';
proc glm data=two plots=diagnostics; class sex color2; model NmbrShrtPrbAftrFrstE=Femur head femur*head/solution;   title 'NmbrShrtPrbAftrFrstE';
proc glm data=two plots=diagnostics; class sex color2; model NumLngE1BfrE2=Femur head femur*head/solution;   title 'NumLngE1BfrE2';
proc glm data=two plots=diagnostics; class sex color2; model NumSnglE1=Femur head femur*head/solution;   title 'NumSnglE1';
proc glm data=two plots=diagnostics; class sex color2; model DurFirstE=Femur head femur*head/solution; title 'DurFirstE';
proc glm data=two plots=diagnostics; class sex color2; model CntrbE1toE=Femur head femur*head/solution;   title 'CntrbE1toE';
proc glm data=two plots=diagnostics; class sex color2; model DurE1FlwdFrstSusE2=Femur head femur*head/solution;   title 'DurE1FlwdFrstSusE2';
proc glm data=two plots=diagnostics; class sex color2; model DurE1FlldFrstE2=Femur head femur*head/solution;   title 'DurE1FlldFrstE2';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurE1FlldSusE2=Femur head femur*head/solution;   title 'TtlDurE1FlldSusE2';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurE1FlldE2=Femur head femur*head/solution;   title 'TtlDurE1FlldE2';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurSnglE1=Femur head femur*head/solution;   title 'TtlDurSnglE1';
proc glm data=two plots=diagnostics; class sex color2; model PrcntPrbE1=Femur head femur*head/solution;   title 'PrcntPrbE1';

*******************************************************************;
******** Variables for E2 *************************;
*******************************************************************;
proc glm data=two plots=diagnostics; class sex color2; model NumE2=Femur head femur*head/solution;   title 'NumE2';
proc glm data=two plots=diagnostics; class sex color2; model NumLngE2=Femur head femur*head/solution;   title 'NumLngE2';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurE2=Femur head femur*head/solution;   title 'TtlDurE2';
proc glm data=two plots=diagnostics; class sex color2; model MnDurE2=Femur head femur*head/solution;   title 'MnDurE2';
proc glm data=two plots=diagnostics; class sex color2; model sdE2=Femur head femur*head/solution;   title 'sdE2';
proc glm data=two plots=diagnostics; class sex color2; model TmFrstSusE2FrstPrb=Femur head femur*head/solution;   title 'TmFrstSusE2FrstPrb';
proc glm data=two plots=diagnostics; class sex color2; model TmFrstSusE2StrtPrb=Femur head femur*head/solution;   title 'TmFrstSusE2StrtPrb';

proc glm data=two plots=diagnostics; class sex color2; model TmFrstE2StrtEPG=Femur head femur*head/solution;   title 'TmFrstE2StrtEPG';
proc glm data=two plots=diagnostics; class sex color2; model TmFrstE2FrmFrstPrb=Femur head femur*head/solution;   title 'TmFrstE2FrmFrstPrb';
proc glm data=two plots=diagnostics; class sex color2; model TmFrstE2FrmPrbStrt=Femur head femur*head/solution;   title 'TmFrstE2FrmPrbStrt';
proc glm data=two plots=diagnostics; class sex color2; model TmLstE2EndRcrd=Femur head femur*head/solution;   title 'TmLstE2EndRcrd';
proc glm data=two plots=diagnostics; class sex color2; model maxE2=Femur head femur*head/solution;   title 'maxE2';
proc glm data=two plots=diagnostics; class sex color2; model PrcntPrbE2=Femur head femur*head/solution;   title 'PrcntPrbE2';
proc glm data=two plots=diagnostics; class sex color2; model PrcntE2SusE2=Femur head femur*head/solution;   title 'PrcntE2SusE2';

*******************************************************************;
******** Variables for E1+E2 *************************;
*******************************************************************;
proc glm data=two plots=diagnostics; class sex color2; model PotE2Indx=Femur head femur*head/solution;   title 'PotE2Indx';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurE=Femur head femur*head/solution;   title 'TtlDurE';
proc glm data=two plots=diagnostics; class sex color2; model TtlDurE1FllwdE2PlsE2=Femur head femur*head/solution;   title 'TtlDurE1FllwdE2PlsE2';
proc glm data=two plots=diagnostics; class sex color2; model TotDurNnPhlPhs=Femur head femur*head/solution;   title 'TotDurNnPhlPhs';*Duration of recording less E1 and E2;
proc glm data=two plots=diagnostics; class sex color2; model TmFrstSusE2=Femur head femur*head/solution;   title 'TmFrstSusE2';
run;
/*
TtlDurNP
DurNnprbBfrFrstE1
DurNnprbBfrFrstD
TmFrmFrstPrbFrstD
TmFrmFrstPrbFrstE
TmFrstSusE2FrstPrb
TmFrstE2StrtEPG
TmFrstE2FrmFrstPrb
TmFrstSusE2
*/;
/*
Proc glm data=two plots=contourfit plots=diagnostics;
model TmFrstSusE2=head;
Proc glm data=two plots=contourfit plots=diagnostics;
model TmFrstSusE2=femur;
run;

Proc glm plots=contourfit plots=diagnostics;
model TmFrmFrstPrbFrstE=femur;
Proc glm plots=contourfit plots=diagnostics;
model TmFrmFrstPrbFrstE=head;
run;

Proc glm plots=contourfit plots=diagnostics;
model TmFrstSusE2=femur;
Proc glm plots=contourfit plots=diagnostics;
model TmFrstSusE2=head;
run;

Proc glimmix data=two plots=residualpanel; class sex color1; model TmFrstSusE2= head|sex|color1; *lsmeans trt/adjust=tukey pdiff lines; title 'ANOVA & LSD of TmFrstSusE2';
proc glm plots=contourfit plots=diagnostics; class sex color1; model TmFrstSusE2= head|sex|color1;
proc glm data=two plots=diagnostics plots=contourfit; class sex color1; model NumPrbs= head sex color1; title 'ANOVA & LSD of NumPrbs';
*/;
data three; set two;
if sex eq "f" and color2 eq "b" then trt2="a";
if sex eq "f" and color2 eq "g" then trt2="b";
if sex eq "m" and color2 eq "b" then trt2="c";
if sex eq "m" and color2 eq "g" then trt2="d";
run;
